<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseBloods.class.php';

Class Bloods {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjBloods = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objBloods = new BaseBloods();
			$objBloods->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objBloods->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objBloods->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objBloods->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objBloods->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objBloods->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objBloods->setDateOfExamination( ( true == isset( $row["date_of_examination"] ) ) ? $row["date_of_examination"] : 'NULL' );
			$objBloods->setHb( ( true == isset( $row["hb"] ) ) ? $row["hb"] : 'NULL' );
			$objBloods->setTotalWbcs( ( true == isset( $row["total_wbcs"] ) ) ? $row["total_wbcs"] : 'NULL' );
			$objBloods->setDifferentialCount( ( true == isset( $row["differential_count"] ) ) ? $row["differential_count"] : 'NULL' );
			$objBloods->setPolymorphs( ( true == isset( $row["polymorphs"] ) ) ? $row["polymorphs"] : 'NULL' );
			$objBloods->setEosinophils( ( true == isset( $row["eosinophils"] ) ) ? $row["eosinophils"] : 'NULL' );
			$objBloods->setBasophi( ( true == isset( $row["basophi"] ) ) ? $row["basophi"] : 'NULL' );
			$objBloods->setLymphocytes( ( true == isset( $row["lymphocytes"] ) ) ? $row["lymphocytes"] : 'NULL' );
			$objBloods->setMonocytes( ( true == isset( $row["monocytes"] ) ) ? $row["monocytes"] : 'NULL' );
			$objBloods->setMalarialParasite( ( true == isset( $row["malarial_parasite"] ) ) ? $row["malarial_parasite"] : 'NULL' );
			$objBloods->setEsrInListHour( ( true == isset( $row["esr_in_list_hour"] ) ) ? $row["esr_in_list_hour"] : 'NULL' );
			$objBloods->setSpecialFindings( ( true == isset( $row["special_findings"] ) ) ? $row["special_findings"] : 'NULL' );
			$objBloods->setBt( ( true == isset( $row["bt"] ) ) ? $row["bt"] : 'NULL' );
			$objBloods->setCt( ( true == isset( $row["ct"] ) ) ? $row["ct"] : 'NULL' );
			$objBloods->setGramsMm( ( true == isset( $row["grams_mm"] ) ) ? $row["grams_mm"] : 'NULL' );
			$objBloods->setEximationCount( ( true == isset( $row["eximation_count"] ) ) ? $row["eximation_count"] : 'NULL' );
			$objBloods->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objBloods->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objBloods->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objBloods->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjBloods, $objBloods );
		}
		return $arrobjBloods;
	}
	public function fetchAllBloods() {
		$result = $this->connection->RunQuery("SELECT * FROM BLOODS");
		$arrobjBloods = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objBloods = new BaseBloods();
			$objBloods->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objBloods->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objBloods->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objBloods->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objBloods->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objBloods->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objBloods->setDateOfExamination( ( true == isset( $row["date_of_examination"] ) ) ? $row["date_of_examination"] : 'NULL' );
			$objBloods->setHb( ( true == isset( $row["hb"] ) ) ? $row["hb"] : 'NULL' );
			$objBloods->setTotalWbcs( ( true == isset( $row["total_wbcs"] ) ) ? $row["total_wbcs"] : 'NULL' );
			$objBloods->setDifferentialCount( ( true == isset( $row["differential_count"] ) ) ? $row["differential_count"] : 'NULL' );
			$objBloods->setPolymorphs( ( true == isset( $row["polymorphs"] ) ) ? $row["polymorphs"] : 'NULL' );
			$objBloods->setEosinophils( ( true == isset( $row["eosinophils"] ) ) ? $row["eosinophils"] : 'NULL' );
			$objBloods->setBasophi( ( true == isset( $row["basophi"] ) ) ? $row["basophi"] : 'NULL' );
			$objBloods->setLymphocytes( ( true == isset( $row["lymphocytes"] ) ) ? $row["lymphocytes"] : 'NULL' );
			$objBloods->setMonocytes( ( true == isset( $row["monocytes"] ) ) ? $row["monocytes"] : 'NULL' );
			$objBloods->setMalarialParasite( ( true == isset( $row["malarial_parasite"] ) ) ? $row["malarial_parasite"] : 'NULL' );
			$objBloods->setEsrInListHour( ( true == isset( $row["esr_in_list_hour"] ) ) ? $row["esr_in_list_hour"] : 'NULL' );
			$objBloods->setSpecialFindings( ( true == isset( $row["special_findings"] ) ) ? $row["special_findings"] : 'NULL' );
			$objBloods->setBt( ( true == isset( $row["bt"] ) ) ? $row["bt"] : 'NULL' );
			$objBloods->setCt( ( true == isset( $row["ct"] ) ) ? $row["ct"] : 'NULL' );
			$objBloods->setGramsMm( ( true == isset( $row["grams_mm"] ) ) ? $row["grams_mm"] : 'NULL' );
			$objBloods->setEximationCount( ( true == isset( $row["eximation_count"] ) ) ? $row["eximation_count"] : 'NULL' );
			$objBloods->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objBloods->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objBloods->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objBloods->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjBloods, $objBloods);
		}
		return $arrobjBloods;
	}
	public function fetchAllBloodsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM BLOODS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjBloods = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objBloods->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objBloods->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objBloods->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objBloods->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objBloods->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objBloods->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objBloods->setDateOfExamination( ( true == isset( $row["date_of_examination"] ) ) ? $row["date_of_examination"] : 'NULL' );
			$objBloods->setHb( ( true == isset( $row["hb"] ) ) ? $row["hb"] : 'NULL' );
			$objBloods->setTotalWbcs( ( true == isset( $row["total_wbcs"] ) ) ? $row["total_wbcs"] : 'NULL' );
			$objBloods->setDifferentialCount( ( true == isset( $row["differential_count"] ) ) ? $row["differential_count"] : 'NULL' );
			$objBloods->setPolymorphs( ( true == isset( $row["polymorphs"] ) ) ? $row["polymorphs"] : 'NULL' );
			$objBloods->setEosinophils( ( true == isset( $row["eosinophils"] ) ) ? $row["eosinophils"] : 'NULL' );
			$objBloods->setBasophi( ( true == isset( $row["basophi"] ) ) ? $row["basophi"] : 'NULL' );
			$objBloods->setLymphocytes( ( true == isset( $row["lymphocytes"] ) ) ? $row["lymphocytes"] : 'NULL' );
			$objBloods->setMonocytes( ( true == isset( $row["monocytes"] ) ) ? $row["monocytes"] : 'NULL' );
			$objBloods->setMalarialParasite( ( true == isset( $row["malarial_parasite"] ) ) ? $row["malarial_parasite"] : 'NULL' );
			$objBloods->setEsrInListHour( ( true == isset( $row["esr_in_list_hour"] ) ) ? $row["esr_in_list_hour"] : 'NULL' );
			$objBloods->setSpecialFindings( ( true == isset( $row["special_findings"] ) ) ? $row["special_findings"] : 'NULL' );
			$objBloods->setBt( ( true == isset( $row["bt"] ) ) ? $row["bt"] : 'NULL' );
			$objBloods->setCt( ( true == isset( $row["ct"] ) ) ? $row["ct"] : 'NULL' );
			$objBloods->setGramsMm( ( true == isset( $row["grams_mm"] ) ) ? $row["grams_mm"] : 'NULL' );
			$objBloods->setEximationCount( ( true == isset( $row["eximation_count"] ) ) ? $row["eximation_count"] : 'NULL' );
			$objBloods->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objBloods->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objBloods->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objBloods->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjBloods, $objBloods );
		}
		return $arrobjBloods;
	}

	public function fetchBloodsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM BLOODS WHERE id = " . $intId );
			$objBloods = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objBloods = new BaseBloods();
			$objBloods->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objBloods->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objBloods->setCasePaperId( ( true == isset( $row["case_paper_id"] ) ) ? $row["case_paper_id"] : 'NULL' );
			$objBloods->setDoctorId( ( true == isset( $row["doctor_id"] ) ) ? $row["doctor_id"] : 'NULL' );
			$objBloods->setChargeId( ( true == isset( $row["charge_id"] ) ) ? $row["charge_id"] : 'NULL' );
			$objBloods->setRemark( ( true == isset( $row["remark"] ) ) ? $row["remark"] : 'NULL' );
			$objBloods->setDateOfExamination( ( true == isset( $row["date_of_examination"] ) ) ? $row["date_of_examination"] : 'NULL' );
			$objBloods->setHb( ( true == isset( $row["hb"] ) ) ? $row["hb"] : 'NULL' );
			$objBloods->setTotalWbcs( ( true == isset( $row["total_wbcs"] ) ) ? $row["total_wbcs"] : 'NULL' );
			$objBloods->setDifferentialCount( ( true == isset( $row["differential_count"] ) ) ? $row["differential_count"] : 'NULL' );
			$objBloods->setPolymorphs( ( true == isset( $row["polymorphs"] ) ) ? $row["polymorphs"] : 'NULL' );
			$objBloods->setEosinophils( ( true == isset( $row["eosinophils"] ) ) ? $row["eosinophils"] : 'NULL' );
			$objBloods->setBasophi( ( true == isset( $row["basophi"] ) ) ? $row["basophi"] : 'NULL' );
			$objBloods->setLymphocytes( ( true == isset( $row["lymphocytes"] ) ) ? $row["lymphocytes"] : 'NULL' );
			$objBloods->setMonocytes( ( true == isset( $row["monocytes"] ) ) ? $row["monocytes"] : 'NULL' );
			$objBloods->setMalarialParasite( ( true == isset( $row["malarial_parasite"] ) ) ? $row["malarial_parasite"] : 'NULL' );
			$objBloods->setEsrInListHour( ( true == isset( $row["esr_in_list_hour"] ) ) ? $row["esr_in_list_hour"] : 'NULL' );
			$objBloods->setSpecialFindings( ( true == isset( $row["special_findings"] ) ) ? $row["special_findings"] : 'NULL' );
			$objBloods->setBt( ( true == isset( $row["bt"] ) ) ? $row["bt"] : 'NULL' );
			$objBloods->setCt( ( true == isset( $row["ct"] ) ) ? $row["ct"] : 'NULL' );
			$objBloods->setGramsMm( ( true == isset( $row["grams_mm"] ) ) ? $row["grams_mm"] : 'NULL' );
			$objBloods->setEximationCount( ( true == isset( $row["eximation_count"] ) ) ? $row["eximation_count"] : 'NULL' );
			$objBloods->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objBloods->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objBloods->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objBloods->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
		}
		return $objBloods;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from bloods order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endBloods(){
		$this->connection->CloseMysql();
	}

}